//
//  JW_ScrollView.m
//  JWMovie
//
//  Created by Jorn.Wu on 15/7/23.
//  Copyright (c) 2015年 Jorn.Wu. All rights reserved.
//

#import "JW_ScrollView.h"
#import "UIImageView+WebCache.h"

@interface JW_ScrollView ()<UIScrollViewDelegate>

@property (nonatomic, strong) UIImageView *imageView;

@end

@implementation JW_ScrollView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.contentSize = CGSizeMake(self.bounds.size.width, 0);
        self.showsHorizontalScrollIndicator = NO;
        self.showsVerticalScrollIndicator = NO;
        _imageView = [[UIImageView alloc] initWithFrame:self.bounds];
        _imageView.contentMode = UIViewContentModeScaleAspectFit;
        [self addSubview:_imageView];
        
        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapAction)];
        [self addGestureRecognizer:singleTap];
        
        UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTapAction)];
        doubleTap.numberOfTapsRequired = 2;
        [self addGestureRecognizer:doubleTap];
        
        [singleTap requireGestureRecognizerToFail:doubleTap];
        
        self.maximumZoomScale = 3.f;
        self.minimumZoomScale = 1.f;
        self.delegate = self;
        
    }
    return self;
}
- (void)singleTapAction{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"NavigationBarHidden" object:nil];
}
- (void)doubleTapAction{
    
    if (self.zoomScale == 1.f) {
        [self setZoomScale:3.f animated:YES];
    }else {
        [self setZoomScale:1.f animated:YES];
    }
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
    return self.imageView;
    
}

- (void)setImageUrlStr:(NSString *)imageUrlStr{
    _imageUrlStr = imageUrlStr;
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:self.imageUrlStr]];
    [self setNeedsLayout];
}
- (void)layoutSubviews{
//    self.imageView.frame = self.frame;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
